﻿using Application.DTO.Department;
using Application.DTO;
using Application.IService.Department;
using Domain.Entity.Department;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;

namespace ApiServer.Controllers.Department
{
    /// <summary>
    /// 部门控制器
    /// </summary>
    [Route("department")]
    [Authorize]
    [ApiController]
    public class DepartmentController : BaseController<Departments>
    {
        private readonly IDepartmentService departmentService;
        public DepartmentController(IDepartmentService departmentService) : base(departmentService)
        {
            this.departmentService = departmentService;
        }
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="dto">部门信息</param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<IActionResult> InsertDepartment(DepartmentFormDTO dto)
        {
            return Ok(await departmentService.InsertDepartment(dto));
        }
        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="dto">修改部门</param>
        /// <returns></returns>
        [HttpPut("update")]
        public async Task<IActionResult> UpdateDepartment(DepartmentFormDTO dto)
        {
            return Ok(await departmentService.UpdateDepartment(dto));
        }
        /// <summary>
        /// 逻辑删除部门
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <returns></returns>
        [HttpDelete("delete")]
        public async Task<IActionResult> SortDeleteDepartment(string ids)
        {
            return Ok(await departmentService.SortDeleteDepartment(ids));
        }
        /// <summary>
        /// 查询部门列表
        /// </summary>
        /// <param name="name">部门名称</param>
        /// <returns></returns>
        [HttpGet("search")]
        public async Task<IActionResult> SearchDepartment(string? name="", int pid=0)
        {
            return Ok(await departmentService.SearchDepartment(name,pid));
        }
    }
}
